package com.mzy.linear_struct.subject;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Author: codermzy
 * @Date: 2024/05/04/下午6:49
 * @Description:
 */
public class 交替合并字符串1768 {

    public static String mergeAlternately(String word1, String word2) {
        int i = 0;
        int j = 0;
        int index = 0;
        char[] ctx = new char[word1.length() + word2.length()];

        // abc
        // eft

        // a e b
        while (i < word1.length() || j < word2.length()) {
            if (i < word1.length()) {
                ctx[index++] = word1.charAt(i++);
            }

            if (j < word2.length()) {
                ctx[index++] = word2.charAt(j++);
            }
        }
        return new String(ctx);
    }

    public static void main(String[] args) {
        System.out.println(mergeAlternately("abc", "eft"));

    }
}
